import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'

import Layout from '@/layout/index.vue'

/**
 * meta : {
    icon: 'ant-svg'/'http:xxx/svg'       图标名称/https：//xxx.svg（https://icones.js.org/collection/ant-desig）
    title: 'title'                       页面标题名称
    affix: true                          始终固定在tagsViews中 不允许删除(初始化一直存在)
    alwaysShow: true                     如果设置为true，将始终显示根菜单
    breadcrumb: true                     如果设置为false，该页面不在面包屑中显示（默认值是True）
    hidden: true                         如果设置为true，页面不显示在侧边栏中（默认值为false）
 *
 * }
 */

/**
 * constantRoutes
 * 没有权限要求的基本页面
 * 所有角色可以访问
 */
export const constantRoutes: RouteRecordRaw[] = [
  {
    path: '/login',
    name: 'Login',
    meta: { hidden: true, title: '登录' },
    component: () => import('@/views/login/index.vue')
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index.vue'),
        meta: {
          icon: 'ant-design:dashboard-outlined',
          title: '首页',
          affix: true, // 固定在tagsViews中 不允许删除
          noCache: true // 不需要缓存
        }
      }
    ]
  },
  {
    path: '/redirect',
    component: Layout,
    meta: { hidden: true },
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index.vue')
      }
    ]
  }
]

const asyncRoutes: RouteRecordRaw[] = [
  {
    path: '/documentation',
    component: Layout,
    redirect: '/documentation/index',
    children: [
      {
        path: 'index',
        name: 'Documentation',
        component: () => import('@/views/documentation/index.vue'),
        meta: { icon: 'ant-design:book-outlined', title: 'documentation' }
      }
    ]
  },

  {
    path: '/guide',
    component: Layout,
    redirect: '/guide/index',
    children: [
      {
        path: 'index',
        name: 'Duide',
        component: () => import('@/views/guide/index.vue'),
        meta: { icon: 'ant-design:cloud-outlined', title: 'guide' }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/menu',
    meta: {
      icon: 'ant-design:branches-outlined',
      title: 'system',
      alwaysShow: true,
      breadcrumb: true
    },
    children: [
      {
        path: 'menu',
        name: 'Menu',
        component: () => import('@/views/system/menu.vue'),
        meta: { icon: 'ant-design:cloud-outlined', title: 'menu' }
      },
      {
        path: 'role',
        name: 'Role',
        component: () => import('@/views/system/role.vue'),
        meta: { icon: 'ant-design:cloud-outlined', title: 'role' }
      },
      {
        path: 'user',
        name: 'User',
        component: () => import('@/views/system/user.vue'),
        meta: { icon: 'ant-design:contacts-outlined', title: 'user' }
      }
    ]
  },
  {
    path: '/splitter',
    component: Layout,
    redirect: '/splitter',
    children: [
      {
        path: '/splitter',
        name: 'Splitter',
        component: () => import('@/views/splitter/index.vue'),
        meta: { icon: 'ant-design:highlight-outlined', title: '卷帘拖拽面板' }
      }
    ]
  },
  {
    path: '/classSchedule',
    component: Layout,
    redirect: '/classSchedule',
    children: [
      {
        path: '/classSchedule',
        name: 'ClassSchedule',
        component: () => import('@/views/classSchedule/index.vue'),
        meta: { icon: 'ant-design:global-outlined', title: '课程表' }
      }
    ]
  },
  {
    path: '/external-link',
    component: Layout,
    children: [
      {
        path: 'http://www.baidu.com',
        redirect: '/',
        meta: { icon: 'ant-design:link-outlined', title: 'link baidu' }
      }
    ]
  }
]
export const routes = [...constantRoutes, ...asyncRoutes]

export default createRouter({
  routes,
  history: createWebHistory(),
  // 是否禁用尾部斜杠
  strict: true,
  scrollBehavior: () => ({ left: 0, right: 0 })
})
